#!/bin/bash
# Whoami | Coded by Ömer Doğan

# colors
GREEN=""
RED=""
REDB=""
YELLOW=""
BLUE=""
RESET=""

if [ -t 1 ]; then
    if tput setaf 0 &>/dev/null; then
        RESET="$(tput sgr0)"
        BOLD="$(tput bold)"
        GREEN="$(tput setaf 46)"
        RED="$(tput setaf 1)"
        REDB="${BOLD}${RED}"
        YELLOW="$(tput setaf 3)"
        BLUE="$(tput setaf 4)"
    else
        RESET="\e[0m"
        BOLD="\e[1m"
        GREEN="\e[32m"
        RED="\e[31m"
        REDB="${BOLD}${RED}"
        YELLOW="\e[33m"
        BLUE="\e[34m"
    fi
fi

# backup dir
BACKUPDIR="/tmp/whoami"
MBACKUPDIR="/tmp/whoami/mac_addresses"

# tor config files
TORRC="/etc/tor/torrc"

# print error and exit
err() {
    echo "${RED}[-]${RESET} ${@}"
    exit 1
}

# print warning
warn() {
    echo "${YELLOW}[!]${RESET} ${@}"
}

# print message
msg() {
    echo "${GREEN}[+]${RESET} ${@}"
}

# print info
info() {
    echo "${BLUE}[*]${RESET} ${@}"
}

# read input
input() {
echo -n "${GREEN}┌─[whoami]─[~]
└─╼ $ ${RESET}"
}

# print banner
banner() {
clear
echo "${GREEN}  ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
                 __
      |  | |__| /  \  /\   |\/| |
      |/\| |  | \__/ /~~\  |  | |
  ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
${RESET}"
}

# set language variables 
# English
English() {
notification_1=("Whoami is already running!")
notification_2=("Check your internet connection and try again!")
notification_3=("Tor is not installed on your system. Setup is starting!")
notification_4=("Tor could not be installed on your system!")
notification_5=("Backup is starting...")
notification_6=("System log files are destroying...")
notification_7=("Please wait this process may take some time...")
notification_8=("Clearing cache...")
notification_9=("Changing the hostname...")
notification_10=("Anonymous DNS servers are setting up...")
notification_11=("The MAC Address of all network interfaces is changing...")
notification_12=("The proper network interface could not be detected. Whoami continues to the next step...")
notification_13=("Time zone is setting to UTC...")
notification_14=("IP address is changing anonymously...")
notification_15=("Anonymization successful. Who are you?")
notification_16=("Whoami is not working anyway")
notification_17=("Restoring hostname from backups...")
notification_18=("DNS servers restoring from backups...")
notification_19=("Network interfaces' MAC addresses are restoring from backups...")
notification_20=("Time zone is setting as default...")
notification_21=("IP address reverting to normal...")
notification_22=("Whoami has been stopped. Be careful.")
lang_t=$(touch .English.txt)
} 
        
# Turkish
Turkish() {
notification_1=("Whoami zaten çalışıyor!")
notification_2=("İnternet bağlantınızı kontrol edip yeniden deneyin!")
notification_3=("Tor sisteminizde kurulu değil. Kurulum başlatılıyor!")
notification_4=("Tor sisteminize kurulamadı!")
notification_5=("Yedekleme başlatılıyor...")
notification_6=("Sistem log dosyaları yok ediliyor...")
notification_7=("Bu işlem biraz zaman alabilir lütfen bekleyin...")
notification_8=("Önbellek temizleniyor...")
notification_9=("Hostname değiştiriliyor...")
notification_10=("Anonim DNS sunucuları ayarlarlanıyor...")
notification_11=("Tüm ağ arayüzlerinin MAC Adresi değiştiriliyor...")
notification_12=("Uygun ağ arayüzü tespit edilemedi. Whoami bir sonraki adıma geçiyor...")
notification_13=("Zaman dilimi UTC olarak ayarlanıyor...")
notification_14=("IP adresi anonim olarak gizleniyor...")
notification_15=("Anonimleştirmme başarılı. Sen kimsin?")
notification_16=("Whoami zaten çalışmıyor !")
notification_17=("Hostname yedeklerden geri yükleniyor...")
notification_18=("DNS sunucuları yedeklerden geri yükleniyor...")
notification_19=("Ağ arayüzlerinin MAC adresleri yedeklerden geri yükleniyor...")
notification_20=("Zaman dilimi varsayılan olarak ayarlanıyor...")
notification_21=("IP adresi normale döndürülüyor...")
notification_22=("Whoami durduruldu. Dikkatli ol.")
lang_t=$(touch .Turkish.txt)
}       

# whoami start functions
start() {

# ask language selection question 
if [ $(id -u) -ne 0 ]; then
     exit 1

else 
    sleep 0.1
fi 
msg "Select a language to continue

[1] English
[2] Türkçe
"
n=0
until [ $n -ge 99 ]
do
command &&
input & read lang
if  [ -z $lang ]; then
     warn "Empty input"
        
elif [ $lang == 1 ]; then        
      English
      break
         
elif [ $lang == 2 ]; then
      Turkish
      break
          
else
      [ $lang -le 5 ] &> /dev/null 
	  warn "Incorrect input"
fi
done

# check backup directory
if [ ! -d $BACKUPDIR ]; then
    mkdir -p $BACKUPDIR
    mkdir -p $MBACKUPDIR
    $lang_t
else 
     err "$notification_1"
     exit 1
fi

# check network connection
if curl ident.me &> /dev/null ; then
	 sleep 0.1
else err "$notification_2"
     exit 1
fi
    
# check and install tor
if tor -h &> /dev/null ; then
	 sleep 0.1
else warn "$notification_3"
     if apt-get install tor -y &> /dev/null ; then
	    sleep 0.1
     else err "$notification_4" && exit 1
     fi
fi

info "$notification_5"

# backup hostname
cat /etc/hostname > $BACKUPDIR/hostname.bak

# backup resolv_conf
mv /etc/resolv.conf $BACKUPDIR/resolv.conf.bak

# backup mac addresses
IFACES=$(ip -o link show | awk -F': ' '{print $2}')
    for IFACE in $IFACES; do
        if [ $IFACE != "lo" ]; then
            cat /sys/class/net/$IFACE/address > $MBACKUPDIR/$IFACE
        fi
    done

# backup timezone
timedatectl show | grep Timezone | sed 's/Timezone=//g' > $BACKUPDIR/timezone.bak

# backup torrc
mv "$TORRC" $BACKUPDIR/torrc.bak

# backup iptables
iptables-save > $BACKUPDIR/iptables.rules.bak

# clean system logs
info "$notification_6"
python - <<END
import os

global logs
global detected_logs

detected_logs = []
possible_logs_list = ['/var/adm/utmp','/usr/adm/utmp','/etc/utmp','/var/log/utmp','/var/run/utmp','/var/adm/utmp','/var/run/utmp','/usr/var/adm/utmp','/var/adm/wtmp','/usr/adm/wtmp','/etc/wtmp','/var/log/wtmp','/var/adm/wtmp','/var/run/wtmp','/usr/var/adm/wtmp','/var/adm/utmpx','/usr/adm/utmpx','/usr/run/utmpx','/etc/utmpx','/var/log/utmpx','/var/run/utmpx','/usr/var/adm/utmpx','/var/adm/wtmpx','/usr/adm/wtmpx','/etc/wtmpx','/var/log/wtmpx','/var/run/wtmpx','/usr/adm/wtmpx','/usr/var/adm/wtmpx','/var/adm/lastlog','/usr/adm/lastlog','/etc/lastlog','/var/log/lastlog','/usr/adm/lastlog','/usr/run/lastlog','/usr/var/adm/lastlog','/var/adm/pacct','/var/account/pacct','/var/log/acct','/var/log/pacct','/var/adm/acct','/var/adm/pacct','/var/account/acct','/usr/adm/acct','/var/log/prelude.log','/var/log/prelude/prelude.log','/var/adm/prelude/prelude.log','/var/adm/prelude/log/prelude.log','/var/adm/log/prelude.log','/var/ids/log/prelude.log','/var/ids/prelude/log/prelude.log','/var/ids/prelude.log','/var/prelude/prelude.log','/var/prelude/log/prelude.log','/home/log/prelude.log','/home/ids/log/prelude.log','/home/prelude/log/prelude.log','/home/ids/prelude.log','/home/prelude/prelude.log','/home/log/prelude.log','/usr/local/var/log/prelude.log','/var/log/prelude-xml.log','/var/log/prelude/prelude-xml.log','/var/adm/prelude/prelude-xml.log','/var/adm/prelude/log/prelude-xml.log','/var/adm/log/prelude-xml.log','/var/ids/log/prelude-xml.log','/var/ids/prelude/log/prelude-xml.log','/var/ids/prelude-xml.log','/var/prelude/prelude-xml.log','/var/prelude/log/prelude-xml.log','/home/log/prelude-xml.log','/home/ids/log/prelude-xml.log','/home/prelude/log/prelude-xml.log','/home/ids/prelude-xml.log','/home/prelude/prelude-xml.log','/home/log/prelude-xml.log','/usr/local/var/log/prelude-xml.log','/var/log/samba/log.smbd','/var/log/samba/log.nmbd','/var/log/log.smbd','/var/log/log.nmbd','/var/log/smb/log.smbd','/var/log/smb/log.nmbd','/home/samba/log.smbd','/home/samba/log.nmbd','/home/samba/log/log.smbd','/home/samba/log/log.nmbd','/home/samba/logs/log.smbd','/home/samba/logs/log.nmbd','/var/log/snort/snort.alert','/var/log/snort.alert','/var/log/ids/snort.alert','/var/ids/snort/snort.alert','/var/ids/snort.alert','/var/snort/snort.alert','/home/snort/snort.alert','/home/snort/log/snort.alert','/home/log/snort/snort.alert','/home/log/snort.alert','/home/ids/snort/snort.alert','/home/ids/snort.alert','/usr/local/ids/snort.alert','/usr/local/var/snort.alert','/usr/local/snort/snort.alert','/usr/local/var/log/snort.alert','/usr/local/snort/log/snort.alert','/usr/local/ids/log/snort.alert','/usr/local/log/snort.alert','/usr/local/log/snort/snort.alert','/var/log/apache2/audit_log','/var/log/apache1/audit_log','/var/log/apache/audit_log','/home/apache2/log/audit_log','/home/apache1/log/audit_log','/home/apache/log/audit_log','/home/http/log/audit_log','/home/httpd/log/audit_log','/var/log/http/audit_log','/var/log/httpd/audit_log','/usr/http/log/audit_log','/usr/httpd/log/audit_log','/usr/local/http/log/audit_log','/usr/local/httpd/log/audit_log','/usr/local/apache/log/audit_log','/usr/local/apache2/log/audit_log','/usr/local/apache1/log/audit_log','/var/www/log/audit_log','/var/http/log/audit_log','/var/httpd/log/audit_log','/var/apache/log/audit_log','/var/apache2/log/audit_log','/var/apache1/log/audit_log','/root/.bash_history','/root/.history','/root/.sh_history','/.bash_history','/.history','/.sh_history','/tmp/.bash_history','/tmp/.sh_history','/tmp/.history','/home/apache/.bash_history','/home/apache/.sh_history','/home/apache/.history','/home/apache1/.bash_history','/home/apache1/.sh_history','/home/apache1/.history','/home/apache2/.bash_history','/home/apache2/.sh_history','/home/apache2/.history','/home/httpd/.bash_history','/home/httpd/.sh_history','/home/httpd/.history','/home/ftpd/.bash_history','/home/ftpd/.sh_history','/home/ftpd/.history','/var/log/apache2/access_log','/var/log/apache2/access_log.1','/var/log/apache2/access_log.2','/var/log/apache2/error_log','/var/log/apache2/error_log.1','/var/log/apache2/error_log.2','/var/log/apache2/ssl_access_log','/var/log/apache2/ssl_access_log.1','/var/log/apache2/ssl_access_log.2','/var/log/apache2/ssl_error_log','/var/log/apache2/ssl_request_log','/var/log/apache2/request_log','/var/log/apache/access_log','/var/log/apache/access_log.1','/var/log/apache/access_log.2','/var/log/apache/error_log','/var/log/apache/error_log.1','/var/log/apache/error_log.2','/var/log/apache/ssl_access_log','/var/log/apache/ssl_error_log','/var/log/apache/ssl_request_log','/var/log/apache/request_log','/var/log/apache1/access_log','/var/log/apache1/error_log','/var/log/apache1/ssl_access_log','/var/log/apache1/ssl_error_log','/var/log/apache1/ssl_request_log','/var/log/apache1/request_log','/var/www/log/access_log','/var/www/log/error_log','/var/www/log/ssl_access_log','/var/www/log/ssl_error_log','/var/www/log/ssl_request_log','/var/www/log/request_log','/var/apache2/access_log','/var/apache2/error_log','/var/apache2/ssl_access_log','/var/apache2/ssl_error_log','/var/apache2/ssl_request_log','/var/apache2/request_log','/home/apache2/access_log','/home/apache2/error_log','/home/apache2/ssl_access_log','/home/apache2/ssl_error_log','/home/apache2/ssl_request_log','/home/apache2/request_log','/var/web/log/access_log','/var/web/log/error_log','/var/web/log/ssl_access_log','/var/web/log/ssl_error_log','/var/web/log/ssl_request_log','/var/web/log/request_log','/var/apache/access_log','/var/apache/error_log','/var/apache/ssl_access_log','/var/apache/ssl_error_log','/var/apache/ssl_request_log','/var/apache/request_log','/home/apache/access_log','/home/apache/error_log','/home/apache/ssl_access_log','/home/apache/ssl_error_log','/home/apache/ssl_request_log','/home/apache/request_log','/var/apache1/access_log','/var/apache1/error_log','/var/apache1/ssl_access_log','/var/apache1/ssl_error_log','/var/apache1/ssl_request_log','/var/apache1/request_log','/home/apache1/access_log','/home/apache1/error_log','/home/apache1/ssl_access_log','/home/apache1/ssl_error_log','/home/apache1/ssl_request_log','/home/apache1/request_log','/usr/apache1/error_log','/usr/apache1/ssl_access_log','/usr/apache1/ssl_error_log','/usr/apache1/ssl_request_log','/usr/apache1/request_log','/usr/local/apache1/error_log','/usr/local/apache1/ssl_access_log','/usr/local/apache1/ssl_error_log','/usr/local/apache1/ssl_request_log','/usr/local/apache1/request_log','/usr/apache2/error_log','/usr/apache2/ssl_access_log','/usr/apache2/ssl_error_log','/usr/apache2/ssl_request_log','/usr/apache2/request_log','/usr/local/apache2/error_log','/usr/local/apache2/ssl_access_log','/usr/local/apache2/ssl_error_log','/usr/local/apache2/ssl_request_log','/usr/local/apache2/request_log','/usr/apache/error_log','/usr/apache/ssl_access_log','/usr/apache/ssl_error_log','/usr/apache/ssl_request_log','/usr/apache/request_log','/usr/local/apache/error_log','/usr/local/apache/ssl_access_log','/usr/local/apache/ssl_error_log','/usr/local/apache/ssl_request_log','/usr/local/apache/request_log','/usr/local/httpd/access_log','/usr/local/httpd/ssl_access_log','/usr/local/httpd/error_log','/usr/local/httpd/ssl_error_log','/usr/local/httpd/ssl_request_log','/home/httpd/access_log','/home/httpd/ssl_access_log','/home/httpd/error_log','/home/httpd/ssl_error_log','/var/adm/SYSLOG','/var/adm/sulog','/var/adm/utmp','/var/adm/utmpx','/var/adm/wtmp','/var/adm/wtmpx','/var/adm/lastlog/username','/usr/spool/lp/log','/var/adm/lp/lpd-errs','/usr/lib/cron/log','/var/adm/loginlog','/var/adm/pacct','/var/adm/dtmp','/var/adm/acct/sum/loginlog','/var/adm/X0msgs','/var/adm/crash/vmcore','/var/adm/crash/unix','/var/adm/pacct','/var/adm/wtmp','/var/adm/dtmp','/var/adm/qacct','/var/adm/sulog','/var/adm/ras/errlog','/var/adm/ras/bootlog','/var/adm/cron/log','/etc/utmp','/etc/security/lastlog','/etc/security/failedlogin','/usr/spool/mqueue/syslog','/var/adm/messages','/var/adm/aculogs','/var/adm/aculog','/var/adm/sulog','/var/adm/vold.log','/var/adm/wtmp','/var/adm/wtmpx','/var/adm/utmp','/var/adm/utmpx','/var/adm/log/asppp.log','/var/log/syslog','/var/log/POPlog','/var/log/authlog','/var/log/auth1.log','/var/adm/pacct','/var/lp/logs/lpsched','/var/lp/logs/lpNet','/var/lp/logs/requests','/var/cron/log','/var/saf/_log','/var/saf/port/log','/var/adm/utmp','/var/log/utmp','/var/run/utmp','/var/adm/utmp','/var/run/utmp','/usr/var/adm/utmp','/var/adm/wtmp','/var/log/wtmp','/var/adm/wtmp','/var/run/wtmp','/usr/var/adm/wtmp','/var/adm/utmpx','/var/log/utmpx','/var/run/utmpx','/usr/var/adm/utmpx','/var/adm/wtmpx','/var/log/wtmpx','/var/run/wtmpx','/usr/var/adm/wtmpx','/var/adm/lastlog','/var/log/lastlog','/usr/var/adm/lastlog','/var/adm/pacct','/var/account/pacct','/var/log/acct','/var/log/pacct','/var/adm/acct','/var/adm/pacct','/var/account/acct','/var/log/prelude.log','/var/log/prelude/prelude.log','/var/adm/prelude/prelude.log','/var/adm/prelude/log/prelude.log','/var/adm/log/prelude.log','/var/ids/log/prelude.log','/var/ids/prelude/log/prelude.log','/var/ids/prelude.log','/var/prelude/prelude.log','/var/prelude/log/prelude.log','/usr/local/var/log/prelude.log','/var/log/prelude-xml.log','/var/log/prelude/prelude-xml.log','/var/adm/prelude/prelude-xml.log','/var/adm/prelude/log/prelude-xml.log','/var/adm/log/prelude-xml.log','/var/ids/log/prelude-xml.log','/var/ids/prelude/log/prelude-xml.log','/var/ids/prelude-xml.log','/var/prelude/prelude-xml.log','/var/prelude/log/prelude-xml.log','/usr/local/var/log/prelude-xml.log','/var/log/samba/log.smbd','/var/log/samba/log.nmbd','/var/log/log.smbd','/var/log/log.nmbd','/var/log/smb/log.smbd','/var/log/smb/log.nmbd','/var/log/snort/snort.alert','/var/log/snort.alert','/var/log/ids/snort.alert','/var/ids/snort/snort.alert','/var/ids/snort.alert','/var/snort/snort.alert','/usr/local/var/snort.alert','/usr/local/var/log/snort.alert','/var/log/apache2/audit_log','/var/log/apache1/audit_log','/var/log/apache/audit_log','/var/log/http/audit_log','/var/log/httpd/audit_log','/var/www/log/audit_log','/var/http/log/audit_log','/var/httpd/log/audit_log','/var/apache/log/audit_log','/var/apache2/log/audit_log','/var/apache1/log/audit_log','/var/log/apache2/access_log','/var/log/apache2/access_log.1','/var/log/apache2/access_log.2','/var/log/apache2/error_log','/var/log/apache2/error_log.1','/var/log/apache2/error_log.2','/var/log/apache2/ssl_access_log','/var/log/apache2/ssl_access_log.1','/var/log/apache2/ssl_access_log.2','/var/log/apache2/ssl_error_log','/var/log/apache2/ssl_request_log','/var/log/apache2/request_log','/var/log/apache/access_log','/var/log/apache/access_log.1','/var/log/apache/access_log.2','/var/log/apache/error_log','/var/log/apache/error_log.1','/var/log/apache/error_log.2','/var/log/apache/ssl_access_log','/var/log/apache/ssl_error_log','/var/log/apache/ssl_request_log','/var/log/apache/request_log','/var/log/apache1/access_log','/var/log/apache1/error_log','/var/log/apache1/ssl_access_log','/var/log/apache1/ssl_error_log','/var/log/apache1/ssl_request_log','/var/log/apache1/request_log','/var/www/log/access_log','/var/www/log/error_log','/var/www/log/ssl_access_log','/var/www/log/ssl_error_log','/var/www/log/ssl_request_log','/var/www/log/request_log','/var/apache2/access_log','/var/apache2/error_log','/var/apache2/ssl_access_log','/var/apache2/ssl_error_log','/var/apache2/ssl_request_log','/var/apache2/request_log','/var/web/log/access_log','/var/web/log/error_log','/var/web/log/ssl_access_log','/var/web/log/ssl_error_log','/var/web/log/ssl_request_log','/var/web/log/request_log','/var/apache/access_log','/var/apache/error_log','/var/apache/ssl_access_log','/var/apache/ssl_error_log','/var/apache/ssl_request_log','/var/apache/request_log','/var/apache1/access_log','/var/apache1/error_log','/var/apache1/ssl_access_log','/var/apache1/ssl_error_log','/var/apache1/ssl_request_log','/var/apache1/request_log','/var/log','/var/adm','/var/spool/mqueue','/var/mail','/var/log/emerge.log','/var/log/Xorg.0.log','/root/.bash_history','/root/.bash_logout','/usr/local/apache/logs','/usr/local/apache/log','/var/apache/logs','/var/apache/log','/var/run/utmp','/var/logs','/var/log','/var/adm','/etc/wtmp','/etc/utmp','/var/log/lastlog','/var/log/syslog','/var/log/messages','/var/log/httpd/access_log','/var/log/httpd/access.log','/var/log/httpd/error_log','/var/log/httpd/error.log','/var/log/apache2/access_log','/var/log/apache2/access.log','/var/log/apache2/error.log','/var/log/apache2/error_log','/var/log/wtmp','/var/log/secure','/var/log/xferlog','/var/log/auth.log','/var/log/lighttpd/lighttpd.error.log','/var/log/lighttpd/lighttpd.access.log','/var/run/utmp','/var/www/logs/access_log','/var/www/logs/access.log','/var/www/logs/error_log','/var/www/logs/error.log','/var/log/apache/access_log','/var/log/apache/access.log','/var/log/apache/error_log','/var/log/apache/error.log','/var/log/yum.log','/etc/httpd/logs/access_log','/etc/httpd/logs/access.log','/etc/httpd/logs/error_log','/etc/httpd/logs/error.log']

for x in possible_logs_list:
	if os.path.isfile(x) == True:
		detected_logs.append(x)
		clean_detected_logs = "shred -vfzu " + x + " > /dev/null 2>&1 && touch " + x + " > /dev/null 2>&1" 
		os.system(clean_detected_logs)
			
END
	info "$notification_7"
	command &&
		for logs in `find / -name "*.log"`; do
				shred -vfzu $logs 
				touch $logs 
		done &> /dev/null
		shred -vfzu Authentication.log Log.log Test Tests.log &> /dev/null

# memory and ram wipe
info "$notification_8"
swapoff -a 
swapon -a 
echo 1024 >/proc/sys/vm/min_free_kbytes
echo 3 >/proc/sys/vm/drop_caches
echo 1 >/proc/sys/vm/oom_kill_allocating_task
echo 1 >/proc/sys/vm/overcommit_memory
echo 0 >/proc/sys/vm/oom_dump_tasks

# hostname change
info "$notification_9"
array[0]="Windows10-Enterprise "
array[1]="Windows10-Pro"
array[2]="Windows10-Enterprise-LTSC "
array[3]="Windows8.1O-EM"
array[4]="Windows8-Enterprise"
array[5]="Windows8.1-Pro"
array[6]="Windows7-Professional"
array[7]="Windows7-Enterprise"
array[8]="Windows7-Ultimate"
array[9]="Windows-Vista-Business"
array[10]="WindowsXP-Professional"
array[11]="macOS11"
array[12]="OSX10.11"
array[13]="MacBook-Air"
array[14]="MacBook"
array[15]="MacBook-Pro"

size=${#array[@]}
index=$(($RANDOM % $size))

echo "127.0.0.1       localhost ${array[$index]}
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters" > /etc/hosts 
echo "${array[$index]}" > /etc/hostname

# configure nameservers
info "$notification_10"
cat >"/etc/resolv.conf" <<EOF
# generated by whoami
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 84.200.69.80
nameserver 84.200.70.40
nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 91.239.100.100
nameserver 89.233.43.71
EOF
    chmod 644 /etc/resolv.conf

# check virtual machine and change mac address
info "$notification_11"
IFACES=$(ip -o link show | awk -F': ' '{print $2}')

changer_func(){
n=0
until [ $n -ge 10 ]
do
command &&
RAND_MAC() {

gen() {
NUM="$(tr -dc '0-9a-f' </dev/urandom | head -c 2)"
echo -n "$NUM:"
}

for c in {1..6}; do

if [ "$c" -lt "6" ]; then
	gen
else
	gen | tr -d ':'
fi

done
}
n=$[$n+1]
out=$(RAND_MAC)
echo $out	
ip link set $IFACE down
ip link set $IFACE address $out
ip link set $IFACE up
done &> /dev/null
}

if [ "$(dmidecode -s system-manufacturer)" == "innotek GmbH" ] || [ "$(dmidecode -s system-manufacturer)" == "VMware, Inc." ] &>/dev/null; then
    if nmcli dev | grep wifi &>/dev/null; then   
         for IFACE in $IFACES; do
                if [ $IFACE != "lo" ] && [ $IFACE != "eth0" ]; then
                     channger_func
                fi
         done
    else
   		warn "$notification_12"
   	fi
else 
     for IFACE in $IFACES; do
           if [ $IFACE != "lo" ] ; then
                changer_func
           fi
      done
fi

# timezone change
info "$notification_13"
timedatectl set-timezone UTC
timedatectl set-timezone UTC &> /dev/null

# configure transparent proxy for tor
info "$notification_14"
readonly tor_uid="$(id -u debian-tor)"

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

iptables -t nat -A OUTPUT -d 10.192.0.0/10 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 9040

iptables -t nat -A OUTPUT -d 127.0.0.1/32 -p udp -m udp --dport 53 -j REDIRECT --to-ports 5353

iptables -t nat -A OUTPUT -m owner --uid-owner $tor_uid -j RETURN
iptables -t nat -A OUTPUT -o lo -j RETURN

for lan in 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16; do
	iptables -t nat -A OUTPUT -d $lan -j RETURN
done

iptables -t nat -A OUTPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 9040

iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -j DROP

iptables -A FORWARD -j DROP

iptables -A OUTPUT -m conntrack --ctstate INVALID -j DROP

iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -m owner --uid-owner $tor_uid -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j ACCEPT

iptables -A OUTPUT -d 127.0.0.1/32 -o lo -j ACCEPT

iptables -A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 9040 --tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT

iptables -A OUTPUT -j DROP

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

cat >"/etc/tor/torrc" <<EOF
VirtualAddrNetworkIPv4 10.192.0.0/10
AutomapHostsOnResolve 1
TransPort 9040 IsolateClientAddr IsolateClientProtocol IsolateDestAddr IsolateDestPort
SocksPort 9050
DNSPort 5353
EOF

cat >"/etc/resolv.conf" <<EOF
nameserver 127.0.0.1
EOF

systemctl --system daemon-reload

if systemctl is-active tor.service >/dev/null 2>&1; then
   systemctl stop tor.service
fi

sysctl -w net.ipv6.conf.all.disable_ipv6=1 &> /dev/null
sysctl -w net.ipv6.conf.default.disable_ipv6=1 &> /dev/null
systemctl start tor.service &>/dev/null
msg "$notification_15"
}

stop() {

# detect language and check whoami status
if   [ -e .English.txt ]; then
     	English     
elif [ -e .Turkish.txt ]; then
     	Turkish
else
	err "$notification_16" && exit 1
fi

# restore all settings  
info "$notification_17"
restore_hostname=$(cat $BACKUPDIR/hostname.bak) 
echo "127.0.0.1       localhost $restore_hostname
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters" > /etc/hosts 
echo "$restore_hostname" > /etc/hostname
        
info "$notification_18"
rm -f /etc/tor/torrc /etc/resolv.conf
mv $BACKUPDIR/resolv.conf.bak /etc/resolv.conf
	    
info "$notification_19"
for device in $(ls $MBACKUPDIR) ; do
    ip link set $device down
    ip link set $device address $(cat $MBACKUPDIR/$device)
    ip link set $device up
done
info "$notification_20"
restore_timezone=$(cat $BACKUPDIR/timezone.bak) && timedatectl set-timezone $restore_timezone

info "$notification_21"
mv $BACKUPDIR/torrc.bak /etc/tor/torrc
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
systemctl stop tor.service
iptables-restore <$BACKUPDIR/iptables.rules.bak
sysctl -w net.ipv6.conf.all.disable_ipv6=0 &> /dev/null
sysctl -w net.ipv6.conf.default.disable_ipv6=0 &> /dev/null

rm -fr $BACKUPDIR/
rm -fr $MBACKUPDIR/
rm -fr .Turkish.txt || rm -fr .English.txt
msg "$notification_22"

}

status() {
banner

RADDR=$(curl -s ip-api.com | sed 's/\"//g;s/\,//g;s/{//g;s/}//g')
TORSTATUS=$(systemctl is-active tor)
 if [[ "${TORSTATUS}" == "active" ]]; then
        msg "${TORSTATUS} (everything is OK)"
    else
        warn "${TORSTATUS} (dead)"
    fi
echo "$RADDR"
}

help() {
banner

echo "  --start  :   After choosing the language, it will make backups and start the program.
  --stop   :   Closes the program using a backup.
  --status :   Provides information about IP address and working status.
  --help   :   This shows the menu."
}

main() {
banner

if [[ "$#" -eq 0 ]]; then
    warn "Whoami: Argument required"
    info "Run'whomai --help' for more information."
    exit 1
fi


while [[ "$#" -gt 0 ]]; do
    
    # run with a root privilege
    if [ $(id -u) -ne 0 ]; then
         sudo bash whoami "$1" && exit 1

    else 
        sleep 0.1
    fi
    
    case "$1" in
    --start)
        start  2> /dev/null && exit 1
        ;;
    --stop)
        stop   2> /dev/null && exit 1 
        ;;
    --status)
        status 2> /dev/null && exit 1
        ;;
    --help)
        help
        exit 1
        ;;
    -- | -* | *)
        warn "Whoami: Invalid option '$1'"
        info "Run 'whomai --help' parameter for more information."
        exit 1
        ;;
    esac    
    shift

done
}

# call main
main "${@}"

# EOF
